<?php

?>
<style type="text/css">
    .item_question{
        font-weight: bold;
        cursor: pointer;
    }
    .item_answer{
        display: none;
        margin-left: 20px;
    }
</style>

<form method="post" action="" class="global_form_box" enctype="application/x-www-form-urlencoded" id="filter_form">
    <input type="hidden" id="order" value="" name="order">
    <input type="hidden" id="order_direction" value="" name="order_direction">
</form>
<h2>
    <?php echo $this->translate('Exam Plugin') ?>
</h2>

<?php if(count($this->navigation)): ?>
<div class='tabs'>
        <?php
        // Render the menu
        //->setUlClass()
        echo $this->navigation()->menu()->setContainer($this->navigation)->render()
        ?>
</div>
<?php endif; ?>

<br />

<?php if(count($this->navigation_sub)): ?>
<div class='tabs'>
        <?php
        // Render the menu
        //->setUlClass()
        echo $this->navigation()->menu()->setContainer($this->navigation_sub)->render()
        ?>
</div>
<?php endif; ?>

<div class='clear'>
    <div class='settings'>
        <form class="global_form">
            <div>
                <?php if($this->paginator->getTotalItemCount() > 0):?>
                <table class='admin_table'>
                    <thead>

                        <tr>
                            <th><a href="javascript:void(0);" onclick="javascript:changeOrder('question', 'ASC');"><?php echo $this->translate("Question") ?></a></th>
                            <th><a href="javascript:void(0);" onclick="javascript:changeOrder('faqcategory_name', 'ASC');"><?php echo $this->translate("Category Name") ?></a></th>
                            <th><?php echo $this->translate("Options") ?></th>
                        </tr>

                    </thead>
                    <tbody>
                            <?php foreach ($this->paginator as $item):?>

                        <tr>
                            <td>
                                <div>
                                    <div class="item_question" onclick="slideDownAns('<?php echo $item['faq_id']?>')"> <?php echo htmlspecialchars($item['question'])?></div>
                                    <div class="item_answer" id="answer_<?php echo $item['faq_id'];?>"> <?php echo $item['answer']?></div>
                                </div>
                            </td>
                            <td><?php echo htmlspecialchars($item['faqcategory_name'])?></td>
                            <td>
                                <a class='smoothbox' href='<?php echo $this->url(array('action' => 'editfaq', 'faq_id' => $item['faq_id']));?>'>
                                            <?php echo $this->translate("edit") ?>
                                </a>
                                |
                                <a class='smoothbox' href='<?php echo $this->url(array('action' => 'deletefaq', 'faq_id' => $item['faq_id']));?>'>
                                            <?php echo $this->translate("delete") ?>
                                </a>
                            </td>
                        </tr>

                            <?php endforeach; ?>

                    </tbody>
                </table>
                <?php else:?>
                <br/>
                <div class="tip">
                    <span><?php echo $this->translate("EXAM_NO_FAQ_DESCRIPTION") ?></span>
                </div>
                <?php endif;?>
                <br/>

                <?php echo $this->htmlLink(array('route' => 'admin_default', 'module' => 'exam', 'controller' => 'faq', 'action' => 'addfaq'), $this->translate('Add New FAQ'), array(
                'class' => 'smoothbox buttonlink',
                'style' => 'background-image: url(application/modules/Core/externals/images/admin/new_category.png);')) ?>

                <br />
                <?php if( $this->paginator->count() > 1 ): ?>
                <br />
                    <?php echo $this->paginationControl($this->paginator, null, null, array(
                    'pageAsQuery' => true,
                    'query' => $this->formValues,
                    //'params' => $this->formValues,
                    )); ?>
                <?php endif; ?>

            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    function slideDownAns(id){
        $('answer_'+id).setStyle('display','block');
    }
    var currentOrder = '<?php echo $this->order ?>';
    var currentOrderDirection = '<?php echo $this->order_direction ?>';
    var changeOrder = function(order, default_direction){
        // Just change direction
        if( order == currentOrder ) {
            $('order_direction').value = ( currentOrderDirection == 'ASC' ? 'DESC' : 'ASC' );
        } else {
            $('order').value = order;
            $('order_direction').value = default_direction;
        }
        $('filter_form').submit();
    }
</script>